﻿//var loader = new widgets.Loader({
//    message: "loading: Soundfont..."
//});

var player;

(function () {
    "use strict";

    WinJS.UI.Pages.define("/pages/home/home.html", {
        // This function is called whenever a user navigates to this page. It
        // populates the page elements with the app's data.
        ready: function (element, options) {
            // TODO: Initialize the page here.
            var item;
            try {
                item = options.item;
            }
            catch (ex) {
            };

            KeyboardInit();

            MIDI.loadPlugin(function () {
                player = MIDI.Player;
                player.timeWarp = 1; // speed the song is played back

                var content = song[songid++ % 3];

                if (typeof (options) != "undefined" && (typeof (options.items) != "undefined"))
                    //if (options != null && options.item.Content != null)
                    content = options.item.Content;
                
                var a = 'data: audio / midi; base64,';
                if (content.indexOf("base64,") == -1) {
                    content = a + content;
                }

                player.loadFile(content, player.start);

                //player.stop();

                viewData = LBet.ParseData(player.data);
                Lab();
                initialized();


                player.addListener(function (data) {
                    if (data.message == 128) { //noteOff
                        ReleaseNote(data.note);
                    }

                    if (data.message == 144) { //noteOn
                        PressNote(data.note);
                    }
                });
                
                //player.stop();
            });
        }
    });
})();
